<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/1
 * Time: 14:59
 */

namespace app\admin\controller;


use app\common\controller\AdminBase;
use app\common\model\Sourcecodem;

class Sourcecode extends AdminBase
{
    /**源码列表
     * @param string $status
     * @param int $page
     * @return mixed
     */
    public function index($status = '', $page = 1)
    {
        $map = [];
        if ($status && $status != 0){
            $map= ['sc_status' => $status];
        }
        $list = Sourcecodem::sourceCodeList($map, $page);
        return $this->fetch('index', ['list' => $list, 'status' => $status]);
    }

    /**审核源码
     * @param $id
     * @param $status
     * @param $res
     * @param $uid
     * @param $sctitle
     */
    public function edit($id, $status, $res, $uid, $sctitle)
    {
        $res1 = false;
        if ($status == 2) {
            $res1 = Sourcecodem::editSourceCode($id, $res, $uid, $sctitle);
        } elseif ($status == 4) {
            $res1 = Sourcecodem::editSourceCode($id, $res, $uid, $sctitle);
        } else {
            $this->error('更新失败');
        }
        if (!$res1) {
            $this->error('更新失败');
        }
        $this->success('更新成功');
    }

    /**源码详情
     * @param $id 源码ID
     * @return mixed
     */
    public function detail($id)
    {
        return $this->fetch('detail', ['detail' => Sourcecodem::detailSourceCode($id)]);
    }
}